package com.ketangpai.admin.utils;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)//属性为NULL不序列化.过滤掉了当返回值为null 的时候的属性。
public class JsonResult<T>  {

    private T data;//数据
    private Integer code;//状态码
    private Object message;//提示信息

    public JsonResult() {
    }

    public JsonResult(Object message) {
        this.message = message;
    }

    public JsonResult(T data, Object message) {
        this.data = data;
        this.message = message;
    }
    public JsonResult( Integer code, Object message) {
        this.code = code;
        this.message = message;
    }

    public JsonResult(T data, Integer code, Object message) {
        this.data = data;
        this.code = code;
        this.message = message;
    }

    public static JsonResult success(Object data) {
        return new JsonResult(data, 200,null);
    }

    public static JsonResult success(String message) {
        return new JsonResult(null,200, message);
    }
    public static JsonResult success(int code, String message) {
        return new JsonResult(code, message);
    }
    public static JsonResult success(Object data, String message) {
        return new JsonResult(data,200, message);
    }
    public static JsonResult success() {
        return JsonResult.success(200,null);
    }


    public static JsonResult error(String message) {
        return new JsonResult(500,message);
    }

    public static JsonResult error() {
        return JsonResult.error("操作失败");
    }

}
